import store from '../store/';
var env = process.env;
var configEnv = 'mock';

let settings = {
  version: configEnv,
  cbs: {
    statusError(err) {
      if (err.resp_code === '0401') {
        this
          .$store
          .dispatch('update_token', {token: ''}); // 移除token 跳转登录 存储token
        this.$message({showClose: true, message: '登录超时,请重新登录', type: 'error'});
        this
          .$router
          .push('/login');
      } else {
        if (err.status !== 404) {
          this.$message({
            showClose: true,
            message: '返回错误：' + err.msg,
            type: 'error'
          });
        } else {
          this
            .$store
            .dispatch('remove_userinfo')
            .then(() => {
              this.$alert(err.resp_code + ',' + err.msg + '！', '登录错误', {
                confirmButtonText: '确定',
                callback: action => {
                  this
                    .$router
                    .push('/login');
                }
              });
            });
        }
      }
    },
    /**
      * ajax请求网络出错时调用
      */
    requestError(err) {
      this
        .$store
        .dispatch('hide_loading');
      if (err.resp_code) {
        this.$message({
          showClose: true,
          message: '请求错误：' + err.resp_code + ',' + err.msg,
          type: 'error'
        });
      }
    }
  }
}

if (configEnv === 'dev') {
  settings.gbs = {
    host: 'http://192.168.50.67:80/api', // 接口根地址。
    db_prefix: 'pos_admin_', // 本地存储的key
    des_key: 'jk23SFDsf13-423j123DF-AjlAS-Fljlk'
  }
} else if(configEnv === 'mock') {
  settings.gbs = {
    host: 'http://yapi.acagrid.com/mock/7/v1', // 接口根地址。
    db_prefix: 'pos_admin_', // 本地存储的key
    des_key: 'jk23SFDsf13-423j123DF-AjlAS-Fljlk'
  }
}

export default settings;
